<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/scripts/jquery-1.9.1.min.js"></script>
</head>
<body>
<form action="${pageContext.request.contextPath}/test02" method="post" enctype="multipart/form-data">
    <input type="text" name="username" value="tomcat"/>
    <input type="text" name="password" value="123456"/>
    <input type="file" name="file"/>
    <input type="submit" value="提交"/>
</form>

<a href="${pageContext.request.contextPath}/testRequestBody">ajax发送json数据</a><br/>
<script type="text/javascript">
    $("a:first").click(function () {
        //点击发送ajax请求，请求带的数据是json
        var employee = {lastName:"张三",email:"aaa@qq.com",gender:0};
        // alert(typeof employee);
        var employeeJson = JSON.stringify(employee);
        // alert(typeof employeeJson);
        $.ajax({
            url:"${pageContext.request.contextPath}/testRequestBody",
            type:"POST",
            data:employeeJson,
            contentType:"application/json",
            success:function (data) {
                alert(data);
            }
        });
        return false;
    });
</script>

</body>
</html>
